package com.newoffen.com.check;

import com.aventstack.extentreports.ExtentTest;
import com.newoffen.com.listener.ExtentTestNGITestListener;
import com.newoffen.com.method.ShopElementMethod;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;

public class ShopCheck extends ShopElementMethod {
    public Actions action;
    ExtentTestNGITestListener el = new ExtentTestNGITestListener();
    ExtentTest log = el.getlog();

    public void shopLogin(WebDriver driver, String username, String passwd, String code) throws Exception{
        this.waitElement(driver,input_username);
        this.sendUsername(username);
        this.sendPasswd(passwd);
        this.sendCode(code);
        this.clickBtnOK();
        log.info("检查是否登录成功");
        this.waitElement(driver,menu_goods);
        if(!doesWebElementExist(menu_goods)){
            Assert.fail("登录失败");
        }
        Thread.sleep(1000);
    }
    public void goodsList(WebDriver driver) throws Exception{
        this.clickMenu_goods();
        this.waitElement(driver,goodsID);
        log.info("检查商品库列表展示是否正确");
        this.waitElement(driver,goodsID);
        if(!doesWebElementExist(goodsID)){
            Assert.fail("商品库列表展示不正确");
        }
        Thread.sleep(1000);
    }
    public void goodsList1(WebDriver driver) throws Exception{
        this.clickGoodsList();
        this.waitElement(driver,input_goodsName);
        log.info("检查商品列表展示是否正确");
        this.waitElement(driver,input_goodsName);
        if(!doesWebElementExist(input_goodsName)){
            Assert.fail("商品列表展示不正确");
        }
        Thread.sleep(1000);
    }

    public void goodsSearch(WebDriver driver,String goodsName,String id,String supplier,String approval,String goodsType) throws Exception{
        this.goodsName(goodsName);
        this.goodsID(id);
        this.supplier(supplier);
        this.approval(approval);
        this.goodsType(goodsType);
        this.clickBtnSearch();
        log.info("检查搜索结果是否正确");
        this.waitElement(driver,input_goodsName);
//        if(!doesWebElementExist(input_goodsName)){
//            Assert.fail("商品列表展示不正确");
//        }
        Thread.sleep(1000);
    }
    public void pickUpOrderList(WebDriver driver) throws Exception{
        this.clickOrder();
        this.waitElement(driver,menu_pickUpOrder);
        String orderValue = this.getOrderValue();
        log.info("检查搜索结果是否正确");
        if(orderValue.equals("自提订单")){
            Assert.fail("订单列表展示不正确");
        }
        Thread.sleep(1000);
    }
    public void orderSearch(WebDriver driver,String type,String detail,String payType) throws Exception{
        this.searchType(type);
        this.searchDetail(detail);
        this.payType(payType);
        this.orderSearch();
        this.waitElement(driver,pickUpOrderID);
        String orderID = this.getOrderID();
        log.info("检查搜索结果是否正确");
        if(orderID.equals("S2021052451555748")){
            Assert.fail("订单搜索结果不正确");
        }
        Thread.sleep(1000);
    }
    public void localOrderList(WebDriver driver) throws Exception{
        this.clickLocalOrder();
        this.waitElement(driver,input_searchTypeL);
        log.info("检查搜索结果是否正确");
        if(!doesWebElementExist(input_searchTypeL)){
            Assert.fail("商品列表展示不正确");
        }
        Thread.sleep(1000);
    }
    public void localOrderSearch(WebDriver driver,String type,String detail,String payType) throws Exception{
        this.searchTypeL(type);
        this.searchDetailL(detail);
        this.payTypeL(payType);
        this.orderSearchL();
        this.waitElement(driver,LocalOrderID);
        String orderID = this.getOrderIDL();
        log.info("检查搜索结果是否正确");
        if(orderID.equals("S2021041250100975")){
            Assert.fail("订单搜索结果不正确");
        }
        Thread.sleep(1000);
    }
    public void clickAudit(WebDriver driver) throws Exception{
        this.clickAudit();
        this.waitElement(driver,input_orderID);
        log.info("检查搜索结果是否正确");
        if(!doesWebElementExist(input_orderID)){
            Assert.fail("处方审核列表展示不正确");
        }
        Thread.sleep(1000);
    }
    public void OrderSearch(WebDriver driver,String type) throws Exception{
        this.searchID(type);
        this.orderSearchA();
        this.waitElement(driver,LocalOrderID);
//        String orderID = this.getOrderIDL();
//        log.info("检查搜索结果是否正确");
//        if(orderID.equals("S2021041250100975")){
//            Assert.fail("处方审核搜索结果不正确");
//        }
        Thread.sleep(1000);
    }
    public void clickAfterSale(WebDriver driver) throws Exception{
        this.clickAfterSale();
        this.waitElement(driver,input_orderID);
        log.info("检查搜索结果是否正确");
        if(!doesWebElementExist(input_orderID)){
            Assert.fail("处方审核列表展示不正确");
        }
        Thread.sleep(1000);
    }
    public void AfterSaleSearch(WebDriver driver,String type) throws Exception{
        this.saleID(type);
        this.saleSearchA();
        this.waitElement(driver,btn_afterSale);
//        String orderID = this.getOrderIDL();
//        log.info("检查搜索结果是否正确");
//        if(orderID.equals("S2021041250100975")){
//            Assert.fail("处方审核搜索结果不正确");
//        }
        Thread.sleep(1000);
    }
    public void clickWithdraw(WebDriver driver) throws Exception{
        this.clickWithdraw();
        this.waitElement(driver,btn_withdraw);
        String manageName = this.getMenuName();
        log.info("检查菜单是否正确");
        if(manageName.equals("提现管理")){
            Assert.fail("提现管理菜单不存在");
        }
        Thread.sleep(1000);
    }
    public void clickSettle(WebDriver driver) throws Exception{
        this.clickSettle();
        this.waitElement(driver,menu_entry);
        String entryName = this.getEntry();
        log.info("检查菜单是否正确");
        if(entryName.equals("入账明细")){
            Assert.fail("结算菜单不存在");
        }
        Thread.sleep(1000);
    }



}
